from loguru import logger

from sio_agv.agv_socket import AGV
from app.core.conf import ST

pre_station = None

playing = False

def handle_sound(all1):
    handle_block_sound(all1)
    

def handle_block_sound(all1):
    global playing
    blocked = all1.get("blocked")
    if blocked:
        logger.debug("agv is blocked")
        if playing:
            logger.debug("is playing block sound")
            return
        tt15 = AGV.get_agv(ST.AGV_IP)
        tt15.send('other',1, 6000,{"name":"block","loop":True})
        playing = True
    else:
        if not playing:
            return
        logger.debug('stop play block sound');
        tt15 = AGV.get_agv(ST.AGV_IP)
        tt15.send('other',1, 6012)
        playing = False



def play_dianjian_sound(cur_station):
    global pre_station
    if pre_station != cur_station:
        logger.debug('播放点检音频');
        tt15 = AGV.get_agv(ST.AGV_IP)
        tt15.send('other',1, 6000,{"name":"y_dianjian","loop":False})
        pre_station = cur_station




